<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../JS/vue.js"></script>
    <style>
        .active{
            background-color: red;
        }
    </style>
</head>
<body>
    <div id="app">
        <ul>
            <li v-for="(item, index) in movies" 
                :class="{active: activeIndex === index}" 
                @click="changeColor(index)">{{item}}</li>
        </ul>
    </div>
    <script>
        const app = new Vue({
            el: '#app',
            data:{
                movies:['海王','哈维','二维'],
                activeIndex: -1 // -1 表示没有选中项
            },
            methods:{
                changeColor: function (index) {
                    this.activeIndex = index;
                }
            }
        })
    </script>
</body>
</html>